package com.yuncheng.spcyApi.service.impl;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.spcyApi.constant.common.LogConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.SpcyQyCpxx;
import com.yuncheng.spcyApi.mapper.SpcyQyCpxxMapper;
import com.yuncheng.spcyApi.service.ISpcyLogService;
import com.yuncheng.spcyApi.service.ISpcyQyCpxxService;
import com.yuncheng.spcyApi.utils.GetUuIdUtils;
import org.springframework.stereotype.Service;
import com.yuncheng.common.base.service.impl.BaseServiceImpl;
import utils.LogUtils;
import utils.ObjectToMapUtils;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description: 审评查验-企业产品信息
 * @Author: yuncheng
 * @Date: 2023-03-17
 * @Version: V1.0
 */
@Service
public class SpcyQyCpxxServiceImpl extends BaseServiceImpl<SpcyQyCpxxMapper, SpcyQyCpxx> implements ISpcyQyCpxxService {

    @Resource
    private ISpcyLogService spcyLogService;

    @Resource
    private SpcyQyCpxxMapper spcyQyCpxxMapper;

    @Override
    public void addQycpxx(SpcyQyCpxx spcyQyCpxx) {
        if (spcyQyCpxx == null && StringUtils.isBlank(spcyQyCpxx.getFqyid()) && StringUtils.isBlank(spcyQyCpxx.getFcpmc())){
            return;
        }
        List<SpcyQyCpxx> cpList = spcyQyCpxxMapper.selectList(new LambdaQueryWrapper<SpcyQyCpxx>()
                .eq(StringUtils.isNotBlank(spcyQyCpxx.getFqyid()),SpcyQyCpxx::getFqyid, spcyQyCpxx.getFqyid())
                .eq(StringUtils.isNotBlank(spcyQyCpxx.getFcpmc()),SpcyQyCpxx::getFcpmc, spcyQyCpxx.getFcpmc()));

        if (CollectionUtils.isEmpty(cpList)) {
            spcyQyCpxx.setId(GetUuIdUtils.ReplaceUuId());
            save(spcyQyCpxx);

            String logContent = "新增企业产品";
            Map<String, Object> cpMap = ObjectToMapUtils.objectToMap(spcyQyCpxx);
            logContent += LogUtils.MapToStringMethod(cpMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_CPXX,logContent,spcyQyCpxx.getId(),LogConstant.LOGS_QY_CPXX, SpcyConstant.LOGS_SYS_TYPE_XZ);
        }
    }
}
